// $codepro.audit.disable assignmentToNonFinalStatic
package officeserver.report;

import java.io.Serializable;

public class Appointment implements Serializable {
    /**
     * 
     */
    private static final long serialVersionUID = 1L;

    private Report report;

    private int doctorID;

    private int patientID;

    private int day;

    private int timeSlot;

    private int apptID;

    private static int apptCount = 0;

    private boolean confirmed = false;

    /**
     * Creates a new Appointment
     * 
     * @param report
     *            creates a new appointment report
     * @param doctorID
     *            creates a new appointment doctorID
     * @param patientID
     *            creates a new appointment patientID
     * @param day
     *            creates a new appointment day
     * @param timeSlot
     *            creates a new appointment timeSlot
     */
    public Appointment(Report report, int doctorID, int patientID, int day,
	    int timeSlot) {
	this.report = report;
	this.doctorID = doctorID;
	this.patientID = patientID;
	this.day = day;
	this.timeSlot = timeSlot;
	apptID = apptCount;
	// System.out.println( "Appointment ID: " + apptID );

	apptCount++;
    }

    private Appointment(Report report, int doctorID, int patientID, int day,
	    int timeSlot, int apptID) {
	this.report = report;
	this.doctorID = doctorID;
	this.patientID = patientID;
	this.day = day;
	this.timeSlot = timeSlot;
	this.apptID = apptID;
	// System.out.println( "Appointment ID: " + apptID );

    }

    /**
     * @return the apptID
     */
    public int getApptID() {
	return apptID;
    }

    /**
     * gets the report
     * 
     * @return report
     */
    public Report getReport() {
	return report;
    }

    /**
     * sets the report
     * 
     * @param report
     */
    public void setReport(Report report) {
	this.report = report;
    }

    /**
     * gets the day
     * 
     * @return day
     */
    public int getDay() {
	return day;
    }

    /**
     * sets the day
     * 
     * @param day
     */
    public void setDay(int day) {
	this.day = day;
    }

    /**
     * gets the time slot
     * 
     * @return timeslot
     */

    public int getTimeSlot() {
	return timeSlot;
    }

    /**
     * sets the time slot
     * 
     * @param time
     */
    public void setTimeSlot(int time) {
	this.timeSlot = time;
    }

    /*
     * (non-Javadoc)
     * 
     * @see java.lang.Object#equals(java.lang.Object)
     */
    public boolean equals(Object obj) {
	Appointment temp = (Appointment) obj;
	return temp.getApptID() == this.apptID;
    }

    /**
     * gets the doctor ID
     * 
     * @return the doctorID
     */
    public int getDoctorID() {
	return doctorID;
    }

    /**
     * gets the patient ID
     * 
     * @return the patientID
     */
    public int getPatientID() {
	return patientID;
    }

    /**
     * deletes the report
     */
    public void delete() {
	this.report.delete();
	report = null;
    }
    
    /**
     * Creates a copy of the appointment
     * 
     * @return
     */
    public Appointment clone() {
	return new Appointment((report == null) ? null : report.clone(),
		doctorID, patientID, day, timeSlot, this.apptID);
    }

    public void updateAppointment(Appointment update) {
	this.day = update.day;
	this.doctorID = update.getDoctorID();
	this.patientID = update.getPatientID();
	if (report == null) {
	    report = (update.getReport() == null) ? null : update.getReport()
		    .clone();
	} else {
	    this.report.updateReport(update.getReport().clone());
	}
	this.timeSlot = update.getTimeSlot();
    }

    /**
     * @return the confirmed
     */
    public boolean isConfirmed() {
	return confirmed;
    }

    /**
     * @param doctorID
     *            the doctorID to set
     */
    public void setDoctorID(int doctorID) {
	this.doctorID = doctorID;
    }

    public void setConfirmed() {
	confirmed = true;
    }
    
    /**
     * This method should check through the passed in Report and check if any of the Treatment in the array is null
     * If so, it should set that specific treatment to null.
     * 
     * @param update
     * 			The report that has a deleted Treatment
     */
    public void removeTreatment(Treatment treatment, Report curReport){
    Treatment temp[]; 
    for (Treatment t : curReport.getTreatments()) {
    	if (t.getTID() != treatment.getTID()) { 
    //		temp.add(t);
    	}
    	}
    }
 }
